package com.sskj.finance.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;

import com.sskj.finance.R;


public class DrawRing extends View {

    // 定义画笔
    private Paint mPaint1;

    private Paint mPaint2;

    private Paint mPaint3;

    private Paint mPaintText;

    @RequiresApi(api = Build.VERSION_CODES.M)
    public DrawRing(Context context, AttributeSet attrs) {
        super(context, attrs);

        mPaint1 = new Paint();
        mPaint1.setAntiAlias(true);
        mPaint1.setColor(ContextCompat.getColor(context,R.color.finan_587));
        // mPaint1.setColor(Color.GREEN);
        //  设置样式为，空心的，这样那园环就出来了
        mPaint1.setStyle(Paint.Style.STROKE);
        // 设置那个圆环的粗细
        mPaint1.setStrokeWidth(25);

        mPaint2 = new Paint();
        mPaint2.setAntiAlias(true);
        mPaint2.setColor(ContextCompat.getColor(context,R.color.finan_bdc));
        // mPaint2.setColor(Color.RED);
        //  设置样式为，空心的，这样那园环就出来了
        mPaint2.setStyle(Paint.Style.STROKE);
        // 设置那个圆环的粗细
        mPaint2.setStrokeWidth(25);

//        mPaint3 = new Paint();
//        mPaint3.setAntiAlias(true);
//        mPaint3.setColor(context.getColor(R.color.ring_test3));
//        // mPaint3.setColor(Color.BLUE);
//        //  设置样式为，空心的，这样那园环就出来了
//        mPaint3.setStyle(Paint.Style.STROKE);
//        // 设置那个圆环的粗细
//        mPaint3.setStrokeWidth(40);

        mPaintText = new Paint();
        mPaintText.setAntiAlias(true);
        mPaintText.setColor(Color.BLACK);
        mPaintText.setTextSize(24);
    }

    private int w;
    private int h;

    private final int MOVE_VALUE = 88;

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        w = MeasureSpec.getSize(widthMeasureSpec);
        h = MeasureSpec.getSize(heightMeasureSpec);
        setMeasuredDimension(w, h);
    }

    /**
     * 最大100
     */
    public void setRate(float rate) {
        this.rate = rate;
        invalidate();
    }

    private float rate;

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        RectF rectF = new RectF(w * 0.2f, h * 0.2f, w * 0.8f, h * 0.8f);

        float currentAnger = 360f * rate / 100f;
        float leftAnger = 360f - currentAnger;
//        canvas.drawArc(rectF, 90, currentAnger + 90, false, mPaint1);
//
//        canvas.drawArc(rectF, currentAnger + 90, currentAnger + 90 + leftAnger, false, mPaint2);
        canvas.drawArc(rectF, 0, currentAnger, false, mPaint1);
//
        canvas.drawArc(rectF, currentAnger, leftAnger,false, mPaint2);
    }


}